import { isBlank, isValidNumber, maxParts } from '@/utils/utilsNew';
import { forceHanlder, numberRules, requiredRule } from './rules';

export const baseRentConf = [
  {
    title: '小区',
    required: true,
    isInput: true,
    key: 'resblockName',
    tips: '修改小区请前往下方端口配置',
    width: '200px',
    disabled: true,
    // contents: [
    //   { key: 'resblockName', type: 'input', width: '200px', placeholder: '输入小区', readonly: true, disabled: true }
    // ],
    rules: [requiredRule]
  },
  {
    title: '区域',
    required: false,
    isMultiple: true,
    contents: [
      { key: 'area', type: 'input', width: '200px', placeholder: '请选择区域', readonly: true },
      { key: 'addr', type: 'input', width: '300px', placeholder: '请输入地址', readonly: true }
    ],
    width: '200px'
  },
  {
    title: '月租金',
    required: true,
    isInput: true,
    key: 'totalPrices',
    width: '200px',
    unit: '元',
    rules: [
      requiredRule,
      {
        validator: (rule, value, callback) => {
          if (!isValidNumber(value)) {
            callback(new Error('必须为数字'));
          } else if (value < 100) {
            callback(new Error('租金必须大于100'));
          } else if (value > 400000) {
            callback(new Error('租金必须小于400000'));
          } else if (isBlank(value)) {
            callback(new Error('不能有空格'));
          } else if (!maxParts(value)) {
            callback(new Error('只能保留2位小数'));
          }
        },
        trigger: 'blur'
      }
    ],
    checkValue: (v) => isValidNumber(v) && maxParts(v) && v >= 100 && v <= 400000,
    force: true
  },
  {
    title: '户型',
    key: 'floorPlan',
    required: true,
    isMultiple: true,
    contents: [
      { key: 'room', type: 'input', width: '100px', unit: '室', base: true, rules: [requiredRule, numberRules] },
      { key: 'hall', type: 'input', width: '100px', unit: '厅', base: true, rules: [requiredRule, numberRules] },
      { key: 'toilet', type: 'input', width: '100px', unit: '卫', base: true, rules: [requiredRule, numberRules] },
      { key: 'cookRoom', type: 'input', width: '100px', unit: '厨', rules: [requiredRule, numberRules] },
      { key: 'balcony', type: 'input', width: '100px', unit: '阳台', rules: [requiredRule, numberRules] }
    ],
    checkValue: (v) => isValidNumber(v) && v <= 15,
    force: true,
    rules: [requiredRule]
  },
  {
    title: '建筑面积',
    required: true,
    isInput: true,
    key: 'buildSize',
    width: '200px',
    unit: '平方米',
    rules: [
      requiredRule,
      {
        validator: (rule, value, callback) => {
          if (!isValidNumber(value)) {
            callback(new Error('必须为数字'));
          } else if (!(value > 0)) {
            callback(new Error('必须大于0'));
          } else if (value > 5000) {
            callback(new Error('建筑面积不能超过5000'));
          } else if (isBlank(value)) {
            callback(new Error('不能有空格'));
          } else if (!maxParts(value)) {
            callback(new Error('只能保留2位小数'));
          }
        },
        trigger: 'blur'
      }
    ],
    checkValue: (v) => isValidNumber(v) && maxParts(v) && v <= 5000 && v > 0,
    force: true
  },
  {
    title: '出租方式',
    required: true,
    key: 'rentType',
    options: ['合租', '整租'],
    default: '合租',
    isRadio: true,
    rules: [requiredRule]
  },
  {
    title: '房屋类型',
    required: true,
    key: 'buildType',
    options: [
      '住宅',
      '复式住宅',
      '公寓',
      '别墅',
      '商铺',
      '写字楼',
      '平房',
      '新里洋房',
      '老公房',
      '动迁房',
      '经济适用房',
      '其他'
    ],
    isRadio: true,
    rules: [requiredRule]
  },
  {
    title: '朝向',
    required: true,
    key: 'direction',
    options: ['东', '南', '西', '北', '西南', '西北', '东南', '东北', '南北', '东西'],
    isRadio: true,
    rules: [requiredRule]
  },
  {
    title: '装修',
    required: true,
    key: 'decorateType',
    options: ['毛坯', '简装', '精装', '豪装'],
    isRadio: true,
    rules: [requiredRule]
  },
  {
    title: '是否配有电梯',
    required: true,
    key: 'elevator',
    options: ['0', '1'],
    format: (v) => (v == '1' ? '否' : '是'),
    isRadio: true,
    rules: [requiredRule]
  },
  {
    title: '所在楼层',
    required: true,
    isInput: true,
    key: 'floor',
    width: '200px',
    unit: '楼',
    tips: '注：若是地下室，请填负数',
    rules: [
      requiredRule,
      {
        validator: (rule, value, callback) => {
          if (!isValidNumber(value) || !maxParts(value, 0)) {
            callback(new Error('必须为数字且整数'));
          } else if (value > 99) {
            callback(new Error('所在楼层不能大于99'));
          } else if (isBlank(value)) {
            callback(new Error('不能有空格'));
          }
        },
        trigger: 'blur'
      }
    ],
    checkValue: (v) => isValidNumber(v) && v < 99 && maxParts(v, 0)
  },
  {
    title: '总楼层',
    required: true,
    isInput: true,
    key: 'totalFloor',
    unit: '层',
    width: '200px',
    rules: [
      requiredRule,
      {
        validator: (rule, value, callback) => {
          if (!isValidNumber(value) || !maxParts(value, 0)) {
            callback(new Error('必须为数字且整数'));
          } else if (!(value >= 1 && value <= 99)) {
            callback(new Error('总楼层不能小于1且不能大于99'));
          } else if (isBlank(value)) {
            callback(new Error('不能有空格'));
          }
        },
        trigger: 'blur'
      }
    ],
    checkValue: (v) => isValidNumber(v) && v < 99 && maxParts(v, 0)
  },
  {
    title: '付款方式',
    required: true,
    key: 'payWay',
    options: [
      '付1押1',
      '付1押2',
      '付2押1',
      '付2押2',
      '付3押1',
      '付3押2',
      '面议',
      '半年付',
      '半年付',
      '半年付押1',
      '半年付不押',
      '年付',
      '年付押1',
      '年付不押'
    ],
    isRadio: true,
    rules: [requiredRule]
  },
  // 传""表示随时，
  {
    title: '最早入住时间',
    required: false,
    key: 'earlyTime',
    isDate: true
  },
  {
    title: '看房时间',
    required: false,
    key: 'approTime',
    options: ['仅周末', '仅工作日', '随时看房', '工作日晚上和周末'],
    isRadio: true
  },
  {
    title: '房屋亮点',
    required: false,
    key: 'roomShine',
    options: ['南北通透', '首次出租'],
    isCheckbox: true
  },
  {
    title: '费用明细',
    required: false,
    key: 'costDetail',
    options: ['水费', '电费', '燃气费', '宽带费', '物业费', '取暖费', '有线电视费', '停车费'],
    isCheckbox: true
  },
  {
    title: '出租要求',
    required: false,
    key: 'rentRequire',
    options: ['只限女生', '中介勿扰', '一家人', '禁止养宠物', '半年起租', '一年起租', '租户稳定', '作息正常', '禁烟'],
    isCheckbox: true
  }
];

const forceConfigs = baseRentConf.filter((v) => v.force);

export const forceHouseInfoHanlder = forceHanlder.bind(null, forceConfigs);

/** 合租才有的配置数据 */
export const joinRentConf = [
  {
    title: '已出租户数',
    required: true,
    isInput: true,
    key: 'overRentNum',
    width: '100px',
    unit: '户',
    rules: [
      requiredRule,
      {
        validator: (rule, value, callback) => {
          if (!isValidNumber(value)) {
            callback(new Error('必须为数字'));
          } else if (isBlank(value)) {
            callback(new Error('不能有空格'));
          }
        },
        trigger: 'blur'
      }
    ],
    checkValue: (v) => isValidNumber(v)
  },
  {
    title: '共合租户数',
    required: true,
    isInput: true,
    key: 'heRentNum',
    width: '100px',
    unit: '户',
    rules: [
      requiredRule,
      {
        validator: (rule, value, callback) => {
          if (!isValidNumber(value)) {
            callback(new Error('必须为数字'));
          } else if (!(value >= 2)) {
            callback(new Error('合租数不能小于2'));
          } else if (isBlank(value)) {
            callback(new Error('不能有空格'));
          }
        },
        trigger: 'blur'
      }
    ],
    checkValue: (v) => isValidNumber(v) && v >= 2
  },
  {
    title: '待租卧室类型',
    required: true,
    key: 'waitRentType',
    options: [0, 1, 2],
    format: (v) => ['主卧', '次卧', '其他'][v],
    isSingleSelect: true,
    rules: [requiredRule]
  },
  {
    title: '待租卧室朝向',
    required: true,
    key: 'waitRentOrientation',
    options: ['东', '南', '西', '北', '西南', '西北', '东南', '东北', '南北', '东西'],
    isSingleSelect: true,
    rules: [requiredRule]
  },
  {
    title: '待租面积',
    required: true,
    key: 'waitRentSize',
    isInput: true,
    width: '200px',
    unit: '平方米',
    rules: [
      requiredRule,
      {
        validator: (rule, value, callback) => {
          if (!isValidNumber(value)) {
            callback(new Error('必须为数字'));
          } else if (value > 5000) {
            callback(new Error('待租面积不能超过5000'));
          } else if (isBlank(value)) {
            callback(new Error('不能有空格'));
          } else if (!maxParts(value)) {
            callback(new Error('只能保留2位小数'));
          }
        },
        trigger: 'blur'
      }
    ],
    checkValue: (v) => isValidNumber(v) && maxParts(2) && v <= 5000
  },
  {
    title: '房间设施',
    required: false,
    key: 'roomEquip',
    options: ['电视', '空调', '床', '暖气', '衣柜', '卫生间', '阳台', '智能门锁'],
    isCheckbox: true
  },
  {
    title: '公共设施',
    required: false,
    key: 'publicEquip',
    options: [
      '冰箱',
      '洗衣机',
      '热水器',
      '宽带',
      '沙发',
      '油烟机',
      '燃气灶',
      '可做饭',
      '电视',
      '空调',
      '衣柜',
      '床',
      '卫生间',
      '智能门锁',
      '阳台',
      '暖气'
    ],
    isCheckbox: true
  }
];

/** 整租 */
export const wholeRentConf = [
  {
    title: '配套设施',
    required: false,
    key: 'matchingFacilitiesList',
    options: [
      '冰箱',
      '洗衣机',
      '热水器',
      '宽带',
      '沙发',
      '油烟机',
      '燃气灶',
      '可做饭',
      '电视',
      '空调',
      '衣柜',
      '床',
      '卫生间',
      '智能门锁',
      '阳台',
      '暖气'
    ],
    isCheckbox: true
  }
];
